package com.java.jvm.heap;

/**
 * 标量替换
 * -Xmx128m -Xms128m -XX:+DoEscapeAnalysis -XX:+PrintGCDetails
 */
public class ObjectScalarReplaceTests {
    public static void main(String args[]) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
           alloc();

        }
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为： " + (end - start) + " ms");
    }

    private static void alloc() {
        //构建对象(对象为聚合量)
        Point point = new Point(1,2);
        //标量替换(标量可以理解为一个不可再分变量-例如8种基本数据类型)
        //int x=1;
        //int y=2;
    }

    static class Point {
        private int x;
        private int y;
        //byte[] data=new byte[1024*1024];
        public Point(int x,int y){
            this.x=x;
            this.y=y;
        }
    }

}
